/*
 * threading.h
 *
 *  Created on: May 19, 2012
 *      Author: burek
 */

#ifndef THREADING_H_
#define THREADING_H_

#include "common-codes.h"

#ifndef WIN32
#include <pthread.h>
#else
typedef void *HANDLE;
#endif

#define CUT_INIT (0)
#define CUT_RUNNING (1)

#ifdef WIN32
typedef int pthread_t;
typedef int pthread_mutex_t;
#else
typedef int HANDLE;
#endif

// Opsti oblik funkcije threada
typedef void *(*CTFPTR) (void *);

// Handlovi i trenutno stanje threada, za Win32 i Posix
typedef struct
{
	pthread_t nix_handle;
	HANDLE win_handle;
	int state;
} CUThread;

// Mutex struktura, za Win32 i Posix
typedef struct
{
	pthread_mutex_t nix_mutex;
	HANDLE win_mutex;
	int state;
} CUMutex;


CUThread * cu_spawnThread(CTFPTR func, void * param);
int cu_joinThread(CUThread * thread);
void cu_sleep(int ms);

int cu_killThread(CUThread * thread);

CUMutex * cu_createMutex();
void cu_lockMutex(CUMutex * m);
void cu_unlockMutex(CUMutex * m);


#endif /* THREADING_H_ */
